package com.opesoft.fw.mvc.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;

public class Checkbox extends InputBase
{
	protected String[] valueArray;

	public int doStartTag() throws JspException
	{
		this.initParentForm();

		if(this.form!=null)
		{
			String[] result=this.form.getArrayPropertyValue(this.name);
			if(result!=null) this.valueArray=result;
		}

		return Tag.EVAL_BODY_INCLUDE;
	}

	public int doEndTag() throws JspException
	{
		String html="<input type=\"checkbox\"";
		if(name!=null) html+=this.htmlProprty("name",name);
		if(value!=null)
		{
			html+=this.htmlProprty("value",value);
			if(this.valueArray!=null)
			{
				for(int i=0;i<this.valueArray.length;i++)
					if(value.equals(this.valueArray[i]))
					{
						html+=" checked";
						break;
					}
			}
		}
		if(other!=null) html+=" "+other;
		html+=">";
		this.write(html);

		this.valueArray=null;
		return super.doEndTag();
	}

}
